<?php
//header ( 'Refresh: 0; url=/404' );
//////////////////////////////////////////// 
//			Обработчик формы			 ///
////////////////////////////////////////////


$_POST['first_name'] = trim($_POST['first_name']);
$_POST['second_name'] = trim($_POST['second_name']);
$_POST['last_name'] = trim($_POST['last_name']);
$_POST['country'] = trim($_POST['country']);
$_POST['mailaddr'] = trim($_POST['mailaddr']);
$_POST['id_referer'] = trim($_POST['id_referer']);
$_POST['numusr'] = trim($_POST['numusr']);
$_POST['timefrom'] = trim($_POST['timefrom']);
$_POST['timeto'] = trim($_POST['timeto']);


 $linktohome = '<a href="/reg.php" class="link_ord">Вернуться к форме</a>';

 

if(empty($_POST['first_name'])) exit('<div id="informet"><span id="exept">Поле "Имя" не заполнено</span>'.$linktohome.'</div>');
if(empty($_POST['second_name'])) exit('<div id="informet"><span id="exept">Поле "Фамилия" не заполнено</span>'.$linktohome.'</div>');
if(empty($_POST['last_name'])) exit('<div id="informet"><span id="exept">Поле "Отчество" не заполнено</span>'.$linktohome.'</div>');
if(empty($_POST['country'])) exit('<div id="informet"><span id="exept">Поле "Город проживания" не заполнено</span>'.$linktohome.'</div>');
if(empty($_POST['mailaddr'])) exit('<div id="informet"><span id="exept">Поле "Адрес Почты" не заполнено</span>'.$linktohome.'</div>');
if(empty($_POST['id_referer']))exit('<div id="informet"><span id="exept">Поле "id пригласившего" не заполнено</span>'.$linktohome.'</div>');
if(empty($_POST['numusr']))exit('<div id="informet"><span id="exept">Поле "номер телефона" не заполнено</span>'.$linktohome.'</div>');
if(empty($_POST['timefrom'])) exit('<div id="informet"><span id="exept">Поле "Звонок с" не заполнено</span>'.$linktohome.'</div>');
if(empty($_POST['timeto']))	exit('<div id="informet"><span id="exept">Поле "Звонок до" не заполнено</span>'.$linktohome.'</div>');
if($_POST['ageres'] != true) exit('<div id="informet"><span id="exept">Подтвердите свой возраст</span>'.$linktohome.'</div>');
if($_POST['userPolicy'] != true) exit('<div id="informet"><span id="exept">Вы не приняли соглашения</span>'.$linktohome.'</div>');
if (!empty($_POST['mailaddr']))
 {
    if(!preg_match("/^[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]{2,3}/",
    $_POST['mailaddr']))    {
       exit('<span id="exept">Поле "Email" должно соответствовать формату somebody@sonewhere.ru</span>');
       }       
 }
 

 

if (!get_magic_quotes_gpc())
{
$_POST['first_name'] = mysql_escape_string($_POST['first_name']);    
$_POST['second_name'] = mysql_escape_string($_POST['second_name']);
$_POST['last_name'] = mysql_escape_string($_POST['last_name']);
$_POST['country'] = mysql_escape_string($_POST['country']);
$_POST['mailaddr'] = mysql_escape_string($_POST['mailaddr']);
//$_POST['id_referer'] = mysql_escape_string($_POST['id_referer']);
//$_POST['numusr'] = mysql_escape_string($_POST['numusr']);
$_POST['timefrom'] = mysql_escape_string($_POST['timefrom']);
$_POST['timeto'] = mysql_escape_string($_POST['timeto']);
}

$timefrom = $_POST['timefrom'];
$timeto = $_POST['timeto'];
$calltime = $timefrom += $timeto;

require_once('_includes/dbconfig.php');
include('sys/id_generator.php');

$sys_uid = $id_new_user;
 
$photo = "no photo";




/////////////////////////////////////
/// Блок регистрации пользователя///
////////////////////////////////////


mysql_query('SET NAMES UTF8');

$query =  "INSERT INTO user_info (name, se_name, lt_name, country, id_ref, mail, photo, tel_num, call_time, uid)
            VALUES('$_POST[first_name]',
                    '$_POST[second_name]',
                    '$_POST[last_name]',
                    '$_POST[country]',
					'$_POST[id_referer]',
                    '$_POST[mailaddr]',
					'".$photo."',
                    '$_POST[numusr]',
					'".$calltime."',
					'".$sys_uid."')";
 
if(mysql_query($query))
{
include('_pages/alert.php');

} else exit("Ошибка при добавлении данных - ".mysql_error());

?>
 